package com.example.chapter0405;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    RadioButton rb_naval,rb_classical,rb_essays;
    RadioGroup radioGroup;
    TextView result;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rb_naval = findViewById(R.id.rb_noval);
        rb_classical = findViewById(R.id.rb_classical);
        rb_essays = findViewById(R.id.rb_essays);

        radioGroup = findViewById(R.id.radioGroup);

        result = findViewById(R.id.textView);

        rb_essays.setChecked(true);
        result.setText("你感兴趣的图书："+rb_essays.getText().toString());

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (R.id.rb_classical == i){
                    result.setText("你感兴趣的图书："+rb_classical.getText().toString());
                    setTitle(String.valueOf(rb_classical.getText()));
                }else if (R.id.rb_essays == i){
                    setTitle(String.valueOf(rb_essays.getText()));
                    result.setText("你感兴趣的图书："+rb_essays.getText().toString());
                }else if (R.id.rb_noval == i){
                    setTitle(String.valueOf(rb_naval.getText()));
                    result.setText("你感兴趣的图书："+rb_naval.getText().toString());
                }
            }
        });
    }
}